window.onload = initPage;

function initPage()
{
    
}

function enableButtonEdit()
{
    buttonEdit = document.getElementById("bUpdateNodo");    
    buttonEdit.onClick = getDetailsNodo("edit");
   
}

function enableButtonCreateArcticle()
{
    buttonCreate = document.getElementById("bCreateArcticle");
    buttonCreate.onClick = getDetailsNodo("createArcticle");
}

function enableButtonDeleteNodo()
{    
    buttonDelete = document.getElementById("bDeleteNodo");
    buttonDelete.onClick = getDetailsNodo("delete");
}

function getDetailsNodo(itemName)
{
    request = createRequest(); 
    
    if(request==null)
    {
        alert("Incapaz de criar a solicitacaoo");
        return;
    }
    
    var params = "action=" + itemName;
    var url = "";
    
    if(itemName == "edit")
    {  
        url = '/nodo/edit';
    }
    else if(itemName == "createArcticle")
    {
        url = '/artigo/create';
    }
    else if(itemName == "delete")
    {
        url = '/nodo/reciveform';
    }
    
    request.open('GET',url + "?" + params,true); 
    request.onreadystatechange = displayDetails;
    request.send();   
}


function displayDetails()
{   
       if(request.readyState == 4)
       {
           if(request.status == 200)
           {     
               detailDiv = document.getElementById("content");
               detailDiv.innerHTML = request.responseText;
           }
       }
}


function createRequest()
{
    try
    {
        request = new XMLHttpRequest();
    }
    catch(tryMS)
    {
       try
       {
           request = new ActveXObject("Msxm12.XMLHTTP");
       } 
       catch(otherMS)
       {
           try
           {
               request = new ActiveXObjetc("Microsoft.XMLHTTP");
           }
           catch(failed)
           {
               request = null;
           }
       }
    }
   
   return request;
}



